@extends('layout.page')
@section('title','行为管理 - 列表')
@section('stylesheet')
    <link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
@endsection

@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>行为管理<small></small></h5>
            </div>
            <div class="ibox-content">

                <div class="">
                    <a href="/ceb/behavior/create" class="btn btn-primary ">添加行为</a>
                </div>
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>备注</th>
                        <th>行为值</th>
                        <th>分类名称</th>
                        <th>分类值</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($behaviorList as $key => $val)
                        <tr class="gradeA">
                            <td></td>
                            <td>{{$val['name']}}</td>
                            <td></td>
                            <td>{{$val['value']}}</td>
                            <td></td>
                            <td></td>
                            <td>
                            </td>
                        </tr>
                        @foreach($val['behavior_list'] as $kk =>$vv)

                            <tr class="gradeA">
                                <td>{{$vv['id']}}</td>
                                <td>&nbsp;|-&nbsp;&nbsp;{{$vv['name']}}</td>
                                <td>{{$vv['remark']}}</td>
                                <td>{{$vv['value']}}</td>
                                <td>{{$vv['type_name']}}</td>
                                <td>{{$vv['type_value']}}</td>

                                <td>
                                    <a href="/ceb/behavior/edit?id={{ $vv['id'] }}">编辑|</a>
                                    <a href="javascript:void(0);" class="_delete" data-val="{{$vv['id']}}">删除</a>
                                </td>
                            </tr>
                        @endforeach
                    @endforeach()

                    </tbody>
                    <tfoot>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>备注</th>
                        <th>行为值</th>
                        <th>分类名称</th>
                        <th>分类值</th>
                        <th>操作</th>
                    </tr>
                    </tfoot>
                </table>
                {{--分页--}}
                <div>
                    <div class="pull-right">
                        {{--{{ $users->appends(['pageSize'=>$pageSize,'searchVal'=>$searchVal])->render()  }}--}}
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('javascript')
    <!-- Sweet alert -->
    <script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script>
        $(document).ready(function () {

            $('._delete').click(function () {
                var id = $(this).data('val');
                var docuElem=$(this);
                swal({
                            title: "您确定要删除这条信息吗",
                            text: "删除后将无法恢复，请谨慎操作！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "删除！",
                            cancelButtonText: "取消",
                            closeOnConfirm: false,
                            closeOnCancel: false
                        },
                        function (isConfirm) {
                            if (isConfirm) {
                                //继续执行
                                $.ajaxSetup({
                                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                                });
                                $.ajax({
                                    type:'post',
                                    url:'/ceb/behavior/delete',
                                    dataType:'json',
                                    data:{id:id},
                                    success: function(data){
                                        data=eval(data);
                                        if(data.code==1){
                                            docuElem.parents('.gradeA').remove();
                                            swal({
                                                title: "操作成功",
                                                type: "success",
                                                timer: 1000,
                                                showCancelButton: false,
                                                closeOnConfirm: false,
                                                closeOnCancel: false
                                            });
                                        }else{
                                            swal({
                                                title: "操作失败",
                                                type: "error",
                                                timer: 1000,
                                                showCancelButton: false,
                                                closeOnConfirm: false,
                                                closeOnCancel: false
                                            });
                                        }
                                    }
                                });

                            } else {
                                swal({
                                    title: "您取消了删除操作！",
                                    type: "error",
                                    timer: 1000,
                                    showCancelButton: false,
                                    closeOnConfirm: false,
                                    closeOnCancel: false
                                });

                            }
                        }
                );
                return false;
            });
        });

    </script>
@endsection


